#include<iostream>
#include<string>

#include<func.h>
using std::cout;
using std::endl;
using std::string;

class Computer{

public:
    //返回的是指针
    static Computer* Instance(){
        if(_computer == nullptr){
            _computer = new Computer(14000,"apple");
        }
        return _computer;
    }
    //记录错误，只有构造函数才能用初始化列表
    void init(double price,string str)
    {
        _price = price;
        _str = str;
    }
    void print(){
        cout<<_computer->_price<<" "<<_computer->_str<<endl;
    }
    static void destory(){
        if(_computer){
            delete _computer;
            _computer = nullptr;
        }
    }
private:
    Computer(double price,string str)
    :_price(price)
    ,_str(str){
        cout<<"调用了构造函数"<<endl;
    }
    ~Computer(){
        cout<<"调用了析构函数"<<endl;
    }
    Computer &operator= (const Computer &rhs) = delete;
    Computer(const Computer &rhs) = delete;
private: 
    double _price;
    string _str; //c++风格字符串
    static Computer *_computer; //申请在堆上

};
//static 外部声明
Computer *Computer::_computer = nullptr;


int main(void){
    Computer::Instance();
    Computer::Instance()->init(15000,"apple");
    Computer::Instance()->print();
    Computer::destory();
}